//
//  SyncTagDataRequest.m
//  Grammar
//
//  Created by Rick on 7/11/13.
//
//

#import "SyncTagDataRequest.h"
#import "Tag.h"
#import "TagManager.h"

@implementation SyncTagDataRequest
- (NSString*)getRequestUrl
{
    return [NSString stringWithFormat:@"%@%@",REQUEST_DOMAIN,@"grammar/syncTags.intf?"];
}

- (ITTRequestMethod)getRequestMethod
{
    return ITTRequestMethodGet;
}

- (void)processResult
{
    NSArray *findArray = [self.resultDic objectForKey:@"syncFind"];
    NSArray *updateArray = [self.resultDic objectForKey:@"syncUpdate"];
    NSArray *deleteArray = [self.resultDic objectForKey:@"syncDelete"];
    
    for (NSDictionary *aTagDic in findArray) {
        Tag *aTag = [[Tag alloc] initWithDataDic:aTagDic];
        [[TagManager sharedManager] addTag:aTag];
        [aTag release];
    }
    
    for (NSDictionary *aTagDic in updateArray) {
        Tag *aTag = [[Tag alloc] initWithDataDic:aTagDic];
        [[TagManager sharedManager] updateTag:aTag];
        [aTag release];
    }
    
    for (NSDictionary *aTagDic in deleteArray) {
        Tag *aTag = [[Tag alloc] initWithDataDic:aTagDic];
        [[TagManager sharedManager] removeTag:aTag];
        [aTag release];
    }
}
@end
